package com.bruce.asurada.sso.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import com.bruce.asurada.common.Result;
import com.bruce.asurada.common.dto.PhoneCodeSentDTO;
import com.bruce.asurada.sso.service.PhoneCodeService;

import lombok.extern.slf4j.Slf4j;

/**
 * SSO服务端控制器
 * 提供单点登录认证服务
 * 
 * @author Bruce
 */
@Slf4j
@RestController
@RequestMapping("/phone")
public class PhoneController {

    @Autowired
    private PhoneCodeService phoneCodeService;

    /**
     * 发送验证码
     * @param phone
     * @return
     */
    @PostMapping("/sendCode")
    @ResponseBody
    public Result<Void> sendCode(@RequestBody PhoneCodeSentDTO phoneCodeSentDTO)throws Exception{

        String phone = phoneCodeSentDTO.getPhone();
        log.info("发送验证码请求，手机号: {}", phone);
        boolean success = phoneCodeService.generateAndSendCode(phone);
        return success ? Result.success() : Result.error("验证码发送失败");
    }
}
